//
//  Extension+UIBarButtonItem.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/19.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(title: String?, imag:String?, target: AnyObject?, action: Selector) {
//  便利构造函数小借助其他特定构造函数
        
        self.init()
        
        let button = UIButton()
        
        if let text = title {
            
            button.setTitle(text, forState: UIControlState.Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(17)
        }
        
        if let img = imag{
            
            button.setImage(UIImage(named:img), forState: UIControlState.Normal)
        }
        
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        button.sizeToFit()
        self.customView = button
    }
}
